//
//  QrCodeCardController.m
//  OnionHome
//
//  Created by fengjie on 2019/9/25.
//  Copyright © 2019 FengJie. All rights reserved.
//

#import "QrCodeCardController.h"
#import "QcodeViewTool.h"
#import "ScanCodeController.h"

@interface QrCodeCardController ()
/**用户头像*/
@property (nonatomic,strong)UIImageView*iconImage;
/**用户名称*/
@property (nonatomic,strong)UILabel*userName;
/**二维码*/
@property (nonatomic,strong)UIImageView*codeImage;


@end

@implementation QrCodeCardController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"名片二维码";
    self.view.backgroundColor = UIColorFromRGB(0xF5F7F5);
    [self addNavigationItemWithImageNames:@[@"扫一扫"] isLeft:NO target:self action:@selector(rightAction) tags:nil];
    [self createUI];
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self setNavBarBackgroundAndNotClearColor];
}
-(void)rightAction{
    ScanCodeController * scanVC = [ScanCodeController new];
    BasseNavigationController * basnav = [[BasseNavigationController alloc] initWithRootViewController:scanVC];
    [self presentViewController:basnav animated:YES completion:nil];
}
-(void)createUI{
    UIImageView * bgimageView = UIImageView.new;
//    bgimageView.backgroundColor = KGrayColor;
    bgimageView.image = IMAGE_NAMED(@"QrCodeBackground");
    ViewRadius(bgimageView, 4);
    
    [self.view addSubview:bgimageView];
    
    [bgimageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(24);
        make.top.mas_equalTo(28);
        make.right.mas_equalTo(-24);
        make.bottom.mas_equalTo(-150);
    }];
    
    UIView * lineView = UIView.new;
    lineView.backgroundColor = SeparatorColor;
    
    
    [bgimageView addSubview:self.userName];
    [bgimageView addSubview:lineView];
    [bgimageView addSubview:self.iconImage];
    [bgimageView addSubview:self.codeImage];
    
    [self.iconImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(16);
        make.right.mas_equalTo(-16);
        make.width.height.mas_equalTo(40);
    }];
    [self.userName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.iconImage.mas_bottom).offset(10);
        make.centerX.mas_equalTo(0);
    }];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(18);
        make.right.mas_equalTo(-18);
        make.height.mas_equalTo(0.5);
        make.top.mas_equalTo(self.userName.mas_bottom).offset(16);
    }];
    [self.codeImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(75);
        make.right.mas_equalTo(-75);
        make.top.mas_equalTo(170);
        make.bottom.mas_equalTo(-80);
    }];
    
    
    UIButton * leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [leftBtn setTitle:@"保存到手机" forState:UIControlStateNormal];
    [leftBtn setTitleColor:UIColorFromRGB(0x273323) forState:UIControlStateNormal];
    leftBtn.titleLabel.font = SYSTEMFONT(16);
    [leftBtn setBackgroundImage:[UIImage createImageWithColor:UIColorFromRGB(0xffffff)] forState:UIControlStateNormal];
    ViewRadius(leftBtn, 5);

    
    UIButton * rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [rightBtn setTitle:@"分享" forState:UIControlStateNormal];
    [rightBtn setTitleColor:UIColorFromRGB(0xFFFFFF) forState:UIControlStateNormal];
    rightBtn.titleLabel.font = SYSTEMFONT(16);
    [rightBtn setBackgroundImage:[UIImage createImageWithColor:UIColorFromRGB(0x009966)] forState:UIControlStateNormal];
    ViewRadius(rightBtn, 5);
    
    [self.view addSubview:leftBtn];
    [self.view addSubview:rightBtn];
    
    [leftBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(24);
        make.bottom.mas_equalTo(-70);
        make.width.mas_equalTo(128);
        make.height.mas_equalTo(38);
    }];
    [rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-24);
        make.bottom.mas_equalTo(-70);
        make.width.mas_equalTo(128);
        make.height.mas_equalTo(38);
    }];

    
}
#pragma mark --懒加载

-(UIImageView*)iconImage{
    if(!_iconImage){
        _iconImage=[UIImageView new];
        ViewRadius(_iconImage, 20);
        _iconImage.image = IMAGE_NAMED(@"userIconDefut");
        _iconImage.image = [Utilis getRandomUserImage];
    }
    return _iconImage;
}
-(UILabel*)userName{
    if(!_userName){
        _userName=[UILabel new];
        _userName.textColor = UIColorFromRGB(0x273323);
        _userName.font = PingFangSC_Medium(22);
        _userName.text = @"大鲨鱼";
    }
    return _userName;
}
-(UIImageView*)codeImage{
    if(!_codeImage){
        _codeImage=[UIImageView new];
//        _codeImage.image = [QcodeViewTool createQcodeViewUrl:@"https:www.baidu.com"];
        _codeImage.image = [UIImage createQRCode:@"https:www.baidu.com" andSize:CGSizeMake(180, 180) andColor:RGBA(6, 41, 15, 0.99)];
    }
    return _codeImage;
}
@end
